<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理后台</title>
    <link rel="stylesheet" href="../../static/admin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet/less" href="../../../static/admin/css/index.less"/>
    <link rel="stylesheet" href="../../static/admin/css/jquery.pagination.css"/>
    <link rel="stylesheet/less" href="../../static/admin/css/user_redact.less"/>
    <script src="../../../static/admin/js/jquery-1.12.3.js"></script>
    <script src="../../../static/admin/layui/layui.js"></script>
    <script src="../../static/admin/js/less.min.js"></script>
    <script src="../../static/admin/js/jquery.pagination.min.js"></script>
    <script src="../../../static/layer/layer.js"></script>

    <!--<script src="js/plugins/pace/pace.min.js"></script>-->
</head>
<style>
    .content img {
        width: 3rem;
    }

    img:hover {
        transform: scale(2, 2);
        transition: .5s transform;
    }

</style>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    {% include "/admin/left.html" %}
    <div class="layui-body">
        <div id="box" class="fl">
            <div class="content">
                <h3>
                    类型列表
                </h3>

                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr>
                        <th width="15%">类型ID</th>
                        <th width="15%">类型名称</th>
                        <th width="15%">状态</th>
                        <th width="15%">操作</th>
                    </tr>
                    </tbody>
                    {% if res %}
                    {% for d in res %}
                            <tr>
                                <td>{{ d.tid }}</td>
                                <td>{{ d.type_name }}</td>
                                <td>
                                    {% if d.status == 1 %}
                                    启用
                                    {% else %}
                                    禁用
                                    {% endif %}
                                </td>
                                <td>
                                    {% if d.status == 2 %}
                                        <button>
                                            <a href="javascript:;" onclick="update_status({{ d.tid }}, 1)">激活</a>
                                        </button>
                                    {% else %}
                                        <button>
                                            <a href="javascript:;" onclick="update_status({{ d.tid }}, 2)">禁用</a>
                                        </button>
                                    {% endif %}
                                </td>
                            </tr>
                {% endfor %}
                {% else %}
                <tr><td colspan="4">暂无数据</td></tr>
                {% endif %}
                </table>
            </div>
            <div id="pagination1" class="page fr" style="margin-right: 1%;">
                <div class="ui-pagination-container">

                </div>
            </div>
        </div>

    </div>
</div>

<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;

    });
</script>
</body>

</html>
<script>

    function delete_admin(id) {
        layer.open({
            content: "删除管理员",
            btn: ['确定', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    type: 'post',
                    url: '/admin/admin_delete',
                    data: {
                        'id': id
                    },
                    success: function (data) {
                        if (data > 0) {
                            layer.msg("操作成功", {time: 2000}, function () {
                                window.location = '/admin/admin_list.html?page=';
                            });

                        } else {
                            layer.msg("操作失败", {time: 2000});
                        }
                    }
                });
            }
        })
    }

    function update_status(id, status) {
        var tt = "";
        if (status == 1) {
            tt = "确定启用"
        } else {
            tt = "确定禁用"
        }
        layer.open({
            content: tt,
            btn: ['确定', '取消'],
            shadeClose: false,
            yes: function () {
                $.ajax({
                    type: 'post',
                    url: '/admin/type_update_status',
                    data: {
                        'tid': id,
                        'status': status
                    },
                    success: function (msg) {
                        if (msg.status == 1) {
                            layer.msg("操作成功", {time: 2000}, function () {
                               location.reload();
                            });
                        } else {
                            layer.msg("操作失败", {time: 2000});
                        }
                    }
                });
            }
        })
    }

</script>
